package com.lwj.liwanjia.view.activity.yikatong;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.MainActivity;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.base.BaseActivity;
import com.lwj.liwanjia.bean.YikatongBean;
import com.lwj.liwanjia.impl.YikatongView;
import com.lwj.liwanjia.presenter.FapiaoPresenter;
import com.lwj.liwanjia.presenter.YikatongPresenter;
import com.lwj.liwanjia.utils.CircleTransform;
import com.lwj.liwanjia.utils.RxBus;
import com.lwj.liwanjia.utils.SpfUtils;
import com.lwj.liwanjia.view.activity.login.LoginActivity;
import com.lwj.liwanjia.view.activity.personal.qian_bao.QianBaoActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class YiKaTongActivity extends BaseActivity implements YikatongView {

    @BindView(R.id.iv_touxiang)
    ImageView ivTouxiang;
    @BindView(R.id.tv_nicheng)
    TextView tvNicheng;
    @BindView(R.id.tv_yikaitong)
    TextView tvYikaitong;
    @BindView(R.id.tv_kaihao)
    TextView tvKaihao;
    @BindView(R.id.tv_yue)
    TextView tvYue;
    @BindView(R.id.tv_bangdingjin)
    TextView tvBangdingjin;
    @BindView(R.id.tv_xiaxian)
    TextView tvXiaxian;
    @BindView(R.id.tv_yewuyuan)
    TextView tvYewuyuan;

    private String token;
    private YikatongPresenter presenter;

    @Override
    protected void initView() {
        presenter = new YikatongPresenter(this);
    }

    @Override
    protected void initData() {

    }

    public void getData() {
        token = SpfUtils.getSpfUtils(this).getToken();
        presenter.getYikatongData(token);

    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_yi_ka_tong;
    }

    @OnClick({R.id.tv_left, R.id.rl_yue})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_left:
                finish();
                break;
            case R.id.rl_yue://余额
                startActivity(new Intent(this, QianBaoActivity.class));
                break;
        }
    }

    @Override
    public void showError(Exception e) {
        Toast.makeText(this, "数据加载失败", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void getYikatongData(YikatongBean yikatongBean) {
        if (yikatongBean.getState() == 0) {
            startActivity(new Intent(this, LoginActivity.class).putExtra("type","一卡通"));
        } else {
            Glide.with(this).load(yikatongBean.getData().getHeadImage()).error(R.mipmap.headportrait).transform(new CircleTransform(this)).into(ivTouxiang);
            tvNicheng.setText(yikatongBean.getData().getNick());
            tvKaihao.setText(yikatongBean.getData().getOneCardId());
            tvYue.setText("￥" + yikatongBean.getData().getOneCardMoney());
            tvBangdingjin.setText("￥" + yikatongBean.getData().getOneCardBoundMoney());
            tvXiaxian.setText(yikatongBean.getData().getIntroducer() + "人");
            tvYewuyuan.setText(yikatongBean.getData().getSalesman() + "人");
        }
    }
}
